package com.lyf.factory;

import org.springframework.beans.factory.FactoryBean;

import java.sql.Connection;
import java.sql.DriverManager;

public class MyBeanFactory implements FactoryBean {
    /**
     * 获取对象实例返回出去
     * connection
     * @return
     * @throws Exception
     */
    @Override
    public Object getObject() throws Exception {
        //加载驱动
        Class.forName("com.mysql.jdbc.Driver");
        //创建连接
        return DriverManager.getConnection("jdbc:mysql://localhost:3306/xsh?useUnicode=true&characterEncoding=utf8"
                ,"cos","123456");
    }

    /**
     * 告知外部这个是什么样的类型数据
     * @return
     */
    @Override
    public Class<?> getObjectType() {
        return Connection.class;
    }

    /**
     * 设置是否为单例
     * @return
     */
    @Override
    public boolean isSingleton() {
        return false;
    }
}
